package com.hc.radius.command;

import java.util.HashMap;
import java.util.Map;

public enum CommandCreater {
     cc;
     
     Map<String,Command> cmds = new HashMap<String,Command>();
     public Command creater(Class<Command> command) {
    	 String name = command.getSimpleName();
    	 if (cmds.containsKey(name)) {
    		 return cmds.get(name);
    	 }
    	Command cmd = null;
		try {
			cmd = command.newInstance();
			cmds.put(name, cmd);
		} catch (InstantiationException e) {
			e.printStackTrace();
		} catch (IllegalAccessException e) {
			e.printStackTrace();
		}
    	return cmd;
     }
     
     public Command creater(String className) {
    	 Class clazz = null;
    	 try {
			clazz = Class.forName(className);
		} catch (ClassNotFoundException e) {
			e.printStackTrace();
			return null;
		}
		
		return creater(clazz);
     }
}
